// Created by WXX on 2021/10/2 11:30
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
public:
    bool rotateString(string A, string B) {
        if (A.size() != B.size()) return false;
        return get_min(A) == get_min(B);
    }

    string get_min(string s) {
        int n = s.size();
        s = s + s;
        int i = 0, j = 1;
        while (i < n && j < n) {
            int k = 0;
            while (k < n && s[i + k] == s[j + k]) k++;
            if (s[i + k] > s[j + k]) i += k + 1;
            else j += k + 1;

            if (i == j) i++;
        }
        int k = min(i, j);
        return s.substr(k, n);
    }
};

int main() {

    cout << Solution().rotateString("abcde", "cdeab") << endl;

    return 0;
}
